import { observable /*, action*/, autorun } from "mobx";

interface MenuPageData {
  title: string;
  content: string;
  pageId: string;
  key: string;
}
interface ImenuUrlData {
  id: any;
  name: string;
  pageId: string;
  pathName: string | null;
}
let portal: string | null = sessionStorage.getItem("portal");
let MenuData: MenuPageData[] | null = null; //activeKey
let menuUrlData: ImenuUrlData[] | null = null;
let clientWidth: number = 1920;
if (portal) {
  MenuData = JSON.parse(portal);
}
let UserInfo: any = null;
let key = sessionStorage.getItem("activeKey");
let activeKey = "";
if (key) {
  activeKey = key;
}
const store = observable({
  LoginUserAdmin: {
    UserInfo: UserInfo,
    setUserInfo: function (value) {
      this.UserInfo = value;
      sessionStorage.setItem("userInfo", JSON.stringify(value));
    },
  },
  PageTab: {
    MenuData: MenuData,
    activeKey: activeKey,
    menuUrlData: menuUrlData,

    setMenuData: function (value) {
      //mobx重新赋值，更新session
      this.MenuData = value;
      sessionStorage.setItem("portal", JSON.stringify(value));
    },
    setActiveKey: function (value) {
      //mobx重新赋值，更新session
      this.activeKey = value;
      sessionStorage.setItem("activeKey", value);
    },
    setmenuUrlData: function (value) {
      this.menuUrlData = value;
      sessionStorage.setItem("menuUrlData", JSON.stringify(value));
    },
  },
  //页面宽度
  pageParameter: {
    clientWidth: clientWidth,
    setclientWidth: function (value) {
      //mobx重新赋值，更新session
      this.clientWidth = value;
      sessionStorage.setItem("clientWidth", JSON.stringify(value));
    },
  },
});
autorun(() => {
  console.log(store.PageTab.activeKey);
});
export default store;
